package com.achievement.controller;

import com.achievement.domain.dto.PaperAuthorDTO;
import com.achievement.service.IPaperAuthorService;
import com.common.annotation.Anonymous;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * PaperAuthorController
 * 成果管理，科研成果，学术论文，作者
 */

@RestController
@RequestMapping("/achievement/paperAuthor")
public class PaperAuthorController extends BaseController {

    @Autowired
    private IPaperAuthorService paperAuthorService;


    /**
     * 根据论文id，查询相关作者信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:paperauthor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(paperAuthorService.getInfoByPaperId(id));
    }

    /**
     * 新增作者
     */
    @PreAuthorize("@ss.hasPermi('achievement:paperauthor:edit')")
    @Log(title = "新增作者", businessType = BusinessType.INSERT)
    @PostMapping(value = "/edit")
    public AjaxResult add(@RequestBody List<PaperAuthorDTO> dto)
    {
        return toAjax(paperAuthorService.add(dto));
    }


    /**
     * 删除作者
     */
    @PreAuthorize("@ss.hasPermi('achievement:paperauthor:remove')")
    @Log(title = "删除作者", businessType = BusinessType.DELETE)
    @DeleteMapping("/del/{id}")
    public AjaxResult remove(@PathVariable("id") String id)
    {
        return toAjax(paperAuthorService.deleteByPaperId(id));
    }

}
